package com.example.charge.service.Impl;

import com.example.charge.dao.ChargeMapper;
import com.example.charge.service.ChargeService;
import com.example.charge.vo.ChargeVo;
import com.example.result.CommonResult;
import com.example.utils.MyPageHelper;
import com.example.utils.NumUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class ChargeServiceImpl implements ChargeService {
    @Autowired
    ChargeMapper chargeMapper;
    /**
     * 收费管理-收费项目管理全查
     * @param chargeChargeMode
     * @return
     */
    @Override
    public CommonResult getCharge(Integer chargeChargeMode) {
        return CommonResult.ok(MyPageHelper.getPageResult(chargeMapper.getCharge(chargeChargeMode)));
    }

    /**
     * 收费管理-收费项目管理删除
     */
    @Override
    public int delCharge(Integer id) {
        int i = chargeMapper.delCharge(id);
        return i;
    }

    /**
     * 收费管理-收费项目管理增改
     * @param chargeVo
     * @return
     */
    @Override
    public int saveOrUpdateCharge(ChargeVo chargeVo) {
        int i = 0;
        if(chargeVo.getId() == 0){
            chargeVo.setChargeDelFlag(0);
            chargeVo.setChargeState(0);
            i = chargeMapper.addCharge(chargeVo);
        }else {
            i = chargeMapper.updateCharge(chargeVo);
        }
        return i;
    }
}

